/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tpevol;

import genetic.GeneticAlgorithm;
import java.util.ArrayList;
import java.util.Collection;
import tpgen.Generator;
import tpgen.manchester.w3org.Construct;
import tpgen.patterns.TransformationPattern;

/**
 *
 * @author shanki
 */
public class TpGa extends GeneticAlgorithm<TpChromosome, TpContext>  {
    
    private int maxVarsPerType;
    private int maxAxioms;
    private int maxTransformations;
    private Collection<Construct> inputForbiddenConstructs;
    private Collection<Construct> outputForbiddenConstructs;
    
    private Generator g;
    private TpContext context;
        
    public TpGa(int populationSize, int maxTime, double pRepro, double pMutate, int maxVarsPerType, int maxAxioms, int maxTransformations, Collection<Construct> inputForbiddenConstructs, Collection<Construct> outputForbiddenConstructs, Evaluator evaluator) {
        super(populationSize, maxTime, pRepro, pMutate);
        
        
        this.g                          = new Generator();
        this.context                    = new TpContext(evaluator);
        
        this.maxVarsPerType             = maxVarsPerType;
        this.maxAxioms                  = maxAxioms;
        this.maxTransformations         = maxTransformations;
        this.inputForbiddenConstructs   = inputForbiddenConstructs;
        this.outputForbiddenConstructs  = outputForbiddenConstructs;
    }
    
    private TransformationPattern generateTp() {
        return g.generate(maxVarsPerType, maxAxioms, maxTransformations, inputForbiddenConstructs, outputForbiddenConstructs);        
    }
    
    @Override
    protected ArrayList<TpChromosome> generateChromosomes(int count) {
        ArrayList<TpChromosome> initial  = new ArrayList<TpChromosome>();
        
        for (int i = 0; i < count; ++i) {
            TpChromosome chromosome  = new TpChromosome(generateTp());
            initial.add(chromosome);
        }
        
        return initial;
    }

    @Override
    protected TpContext getContext() {
        return context;
    }    
}
